package vn.ugame.model.bl;

import java.sql.SQLException;
import vn.ugame.exception.DataConnectionFailed;
import vn.ugame.exception.ExceptionCode;
import vn.ugame.exception.InvalidArgumentException;
import vn.ugame.exception.InvalidEntityClass;
import vn.ugame.model.dal.OrderDA;
import vn.ugame.model.entity.Order;

public class OrderService {

    public void activateApp(String code, String imei)
            throws InvalidArgumentException, DataConnectionFailed, SQLException,
            InvalidEntityClass {
        OrderDA orderDA = new OrderDA();
        try {
            orderDA.activatedItem(code, imei);
        } catch (SQLException ex) {
            if (Integer.parseInt(ex.getSQLState()) == ExceptionCode.ER_INVALID_ACTIVATED_CODE) {
                throw new InvalidArgumentException(ExceptionCode.ER_INVALID_ACTIVATED_CODE);
            }else{
                throw ex;
            }
        }
    }

    public Order findOrderByActivatedCode(String code)
            throws DataConnectionFailed, SQLException, InvalidEntityClass {
        OrderDA orderDA = new OrderDA();
        return orderDA.findOrderByActivatedCode(code);
    }

    public Order findOrderByIMEI(String imei) 
            throws DataConnectionFailed, SQLException, InvalidEntityClass {
        OrderDA orderDA = new OrderDA();
        return orderDA.findOrderByIMEI(imei);
    }
}
